package cn.tedu.coolshark12.mapper;

import cn.tedu.coolshark12.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {

    //添加商品
    @Insert("insert into product values(null,#{title},#{url},#{price},#{oldPrice},#{viewCount},#{saleCount},#{created},#{categoryId})")
    void insert(Product product);

    //查询商品
    @Select("select id,title,url,price,sale_Count from product")
    @Result(property = "saleCount",column = "sale_count")
    List<Product> select();

    //通过ID查询图片的名字
    @Select("select url from product where id=#{id}")
    String selectUrlById(int id);

    //删除图片
    @Delete("delete from product where id=#{id}")
    void deleteById(int id);

    //首页展示商品
    @Select("select id,title,url,price,old_price,sale_count from product")
    @Result(property = "oldPrice",column = "old_price")
    @Result(property = "saleCount",column = "sale_count")
    List<Product> selectIndex();
}
